<?php
/* fuente original de file upload example 
  http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
*/

session_start();

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
include '../../config.php';
include './dbOpenConn.php';

$cat=$_POST['cat'];
$desc=$_POST['description'];
$date=date($_POST['date']);
$name=$_POST['name'];
//if(isset($_POST['author']))$author=$_POST['author'];
//else $author=;
$author=$_POST['author'];
$owner=$_GET['id'];
if (isset($_POST['problemSelect'])) $problemId=$_POST['problemSelect'];
else $problemId="";

$query = "INSERT INTO files (name, type, size, data, ownerId, author, description, date , category, filename, problemId) ".
"VALUES ('$name' ,'$fileType', '$fileSize', '$content', '$owner', '$author', '$desc', '$date', '$cat', '$fileName', '$problemId')";

mysql_query($query) or die('Error, query failed'); 

//include 'library/closedb.php';
mysql_close();
//echo "<br>File $fileName uploaded<br>";
header("Location:../../index.php?mode=muestraArchivosDesk&id=$owner");
/*echo "<script type=\"text/javascript\">".
      "<!--".
      "window.location = \"../desktop/files.php\"".
       "//-->".
       "</script>";
	   */
} 
?>